#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>
    button {
        background: #758ef0;
        color: #FFF;
        border: none;
        border-radius: 15px;
    }
</style>
#end

#define js()
<script type="text/javascript">
    var now = new Date();
    var start = now.getTime();  // 将当前时间转换为时间戳
    var end = start + 24*60*60*1000*30; //结束时间

    layui.use(['form', 'layer', 'laydate', 'layedit'], function () {
        // 操作对象
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , layedit = layui.layedit
            , $ = layui.jquery;

        layedit.build('brief', {
            height: 180 //设置编辑器高度
        }); //建立编辑器

        var startDate = laydate.render({
            elem: '#publicTime'
            ,type: 'datetime'
            ,format: 'yyyy-MM-dd HH:mm:ss'
            ,min: start
            ,max: end
            ,done: function(value, date){
                endDate.config.value = value;
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1,
                    date: date.date+1
                };
                endDate.config.max ={
                    year:date.year,
                    month:date.month,
                    date: date.date-1
                };
            }
        });
        var endDate = laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
            ,format: 'yyyy-MM-dd HH:mm:ss'
            ,min: start
            ,max: end
        });

        function sanityn() {
            var publicTime = $('#publicTime').val();
            var endTime = $('#endTime').val();
            if (publicTime > endTime)
                return "发布时间不能大于结束时间！";
            if (publicTime < new Date() || endTime < new Date())
                return "时间不能小于当前时间！";
            return null;
        }

        form.on('submit(sub)', function (data) {
            var msg;
            if ((msg = sanityn()) == null){
                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/project/isPublic?id=' + $('#id').val(),
                    data: $.param(data.field),
                    loadFlag: true,
                    success: function (data) {
                        pop_close();
                        setTimeout(function () {
                            return true;
                        }, 3000);
                    },
                    error: function (data) {
                        console.log(data);
                    }
                });
            }else {
                layer.msg(msg);
            }
            return false;
        });
    });

</script>
#end

#define content()
<div class="x-body">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>请填写发布日期</legend>
    </fieldset>
    <form id="person" class="layui-form x-center">
        <div class="layui-form-pane">
            <!--隐藏id-->
            <input type="text" id="id" name="id" class="layui-input layui-disabled layui-hide" value="#(model.id)"/>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 120px">发布期限</label>
                <div class="layui-input-inline">
                    <input type="text" id="publicTime" name="publicTime" class="layui-input" lay-verify="datetime" lay-verify="required" placeholder=" - "/>
                </div>
                <div class="layui-form-mid">至</div>
                <div class="layui-input-inline">
                    <input type="text" id="endTime" name="endTime" class="layui-input" lay-verify="datetime" lay-verify="required" placeholder=" - ">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 120px">项目名称</label>
                <div class="layui-inline" style="float: left;">
                    <p style="margin-left: 20px;margin-top: 8px">#(model.name)</p>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 120px">项目类型</label>
                <div class="layui-inline" style="float: left; width: 180px">
                    <p style="margin-left: 20px;margin-top: 8px">#(model.typeName)</p>
                </div>
                <label class="layui-form-label"style="width: 120px">预计金额</label>
                <div class="layui-inline" style="float: left;">
                    <p style="margin-left: 20px;margin-top: 8px">#number(model.amount, ",###")元</p>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"style="width: 120px">地址</label>
                <div class="layui-inline" style="float: left;">
                    <p style="margin-left: 20px;margin-top: 8px">#(model.site)</p>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"style="width: 120px">简介</label>
                <div class="layui-inline">
                    <textarea class="layui-textarea" id="brief" name="brief" disabled>#(model.brief)</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="sub" align="center">提交</button>
                </div>
            </div>

        </div>
    </form>
</div>
#end